
import junit.framework.TestCase;
import org.junit.Test;
import java.math.BigDecimal;

/**
 * Created by hp on 2017/4/20.
 */
public class ComplexTest extends TestCase {
    Complex a=new Complex(14,4);
    Complex b=new Complex(5,-2);
    Complex c=new Complex(2,1);
    Complex d=new Complex(4,0);
    Complex m=new Complex();
    @Test
    public void testGetRealPart() throws Exception {
        assertEquals(14.0,a.getRealPart());
        assertEquals(5.0,b.getRealPart());
    }

    @Test
    public void testGetImagePart() throws Exception {
        assertEquals(4.0,a.getImagePart());
        assertEquals(-2.0,b.getImagePart());
    }

    @Test
    public void testSetRealPart() throws Exception {
        m.setRealPart(1);
        assertEquals(1.0,m.getRealPart());
    }

    @Test
    public void testSetImagePart() throws Exception {
        m.setImagePart(4);
        assertEquals(4.0,m.getImagePart());
    }

    @Test
    public void testComplexAdd() throws Exception {
        m=a.ComplexAdd(b);
        assertEquals("(19.0+2.0i)",m.toString());
        m=a.ComplexAdd(c);
        assertEquals("(16.0+5.0i)",m.toString());
    }

    @Test
    public void testComplexSub() throws Exception {
        m=b.ComplexSub(a);
        assertEquals("(9.0+6.0i)",m.toString());
        m=c.ComplexSub(b);
        assertEquals("(3.0--3.0i)",m.toString());
    }

    @Test
    public void testComplexMultib() throws Exception {
        m=a.ComplexMultib(b);
        assertEquals("(70.0--8.0i)",m.toString());
        m=a.ComplexMultib(c);
        assertEquals("(28.0+4.0i)",m.toString());

    }
    @Test
    public void testComplexDiv() throws Exception {
        m=c.ComplexDiv(a);
        assertEquals("(7.0+4.0i)",m.toString());
        m=c.ComplexDiv(b);
        assertEquals("(2.5--2.0i)",m.toString());

    }

}